Skip to content

fix(openapi): document arrayBuffer bodies#341

Open
lxy2500798479 wants to merge 1 commit into
elysiajs:mainfrom
lxy2500798479:fix/arraybuffer-request-body
Open

fix(openapi): document arrayBuffer bodies#341
lxy2500798479 wants to merge 1 commit into
elysiajs:mainfrom
lxy2500798479:fix/arraybuffer-request-body

Conversation

@lxy2500798479
Copy link
Copy Markdown

@lxy2500798479 lxy2500798479 commented Jun 1, 2026

Closes elysiajs/elysia#1825

Problem

Routes using parse: "arrayBuffer" with a body schema produced an OpenAPI request body with an empty content object:

{
  "requestBody": {
    "content": {}
  }
}

That makes OpenAPI clients infer the request body as missing or undefined.

Fix

Map arrayBuffer request parsers to application/octet-stream when generating request body content. The same mapping is also used when the parser is already declared as application/octet-stream.

Tests

Added a regression in test/openapi/to-openapi-schema.test.ts for:

  • parse: "arrayBuffer"
  • binary body schema description
  • generated requestBody.content["application/octet-stream"]

Verification run:

  • bun test test/openapi/to-openapi-schema.test.ts
  • git diff --check
  • bun run build
  • PATH="$PWD/node_modules/.bin:$PATH" bun run test

Summary by CodeRabbit

  • New Features

    • Added support for binary request payloads in OpenAPI schema generation. Binary data is now properly documented with application/octet-stream content type, enabling accurate API documentation for endpoints that accept binary data.
  • Tests

    • Added test coverage for binary request payload handling in OpenAPI conversion.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Jun 1, 2026

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 2b5c2d23-a192-486d-9df7-a48fe6406432

📥 Commits

Reviewing files that changed from the base of the PR and between dabaa94 and cb88cc1.

📒 Files selected for processing (2)
  • src/openapi.ts
  • test/openapi/to-openapi-schema.test.ts

Walkthrough

This PR fixes the empty content object in OpenAPI specs when using parse: 'arrayBuffer' with body schemas. It adds handler cases for binary payloads to map them to application/octet-stream media type, plus a test validating the generated schema.

Changes

Binary Request Body Support

Layer / File(s) Summary
arrayBuffer to application/octet-stream mapping
src/openapi.ts, test/openapi/to-openapi-schema.test.ts
Added switch cases handling 'arrayBuffer' and 'application/octet-stream' parse modes to map binary request bodies to application/octet-stream content type in the OpenAPI schema. A new test case verifies the mapping produces the correct media type with schema description and required: true.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

Possibly related issues

  • #1825: Directly addresses the reported issue where parse: 'arrayBuffer' produces empty content in OpenAPI spec—this PR implements the exact fix of adding arrayBuffer → application/octet-stream handler.

Poem

♡ Binary bodies left out in the cold~
No more empty content, the spec's made whole ♡
arrayBuffer finally gets its media type~ (´・ω・`)
application/octet-stream shines so bright~
Such a small fix, yet oh-so-right~ ୧༼ಠ益ಠ༽୨

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main change—adding support for documenting arrayBuffer bodies in OpenAPI generation—making it clear and directly related to the changeset.
Linked Issues check ✅ Passed The PR fully addresses issue #1825 by mapping arrayBuffer parsers to application/octet-stream in request body content generation and includes a regression test.
Out of Scope Changes check ✅ Passed All changes are directly scoped to fixing the arrayBuffer OpenAPI documentation issue; no unrelated modifications are present.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 ESLint

If the error stems from missing dependencies, add them to the package.json file. For unrecoverable errors (e.g., due to private dependencies), disable the tool in the CodeRabbit configuration.

src/openapi.ts

ESLint skipped: missing config or dependency (missing-dependency). The ESLint configuration references a package that is not available in the sandbox.

test/openapi/to-openapi-schema.test.ts

ESLint skipped: the ESLint configuration for this file references a package that is not available in the sandbox.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

parse: 'arrayBuffer' produces empty content in OpenAPI spec

1 participant